﻿using System;
using System.Globalization;
using System.Text.RegularExpressions;
using Avalonia.Data.Converters;

namespace iOSClub.App.Desktop.Converters;

public class SimpleTimeConverter : IValueConverter
{
    public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
    {
        if (value is not string s) return value;
        if (string.IsNullOrEmpty(s)) return s;
        var match = Regex.Match(s, "(.*)T(.*?):(.*)");
        return match.Groups.Count < 3 ? s : $"{byte.Parse(match.Groups[2].Value)}:00";
    }

    public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
    {
        return value;
    }
}